

# Create your models here.
# users/py

from datetime import datetime

from django.db.models import *
from django.contrib.auth.models import AbstractUser
# from organization.models import CityDict

class UserProfile(AbstractUser):
    '''
    管理员
    '''
    gender_choices = (
        ('male','男'),
        ('female','女')
    )
    nick_name = CharField('昵称',max_length=50,default='')
    birthday = DateField('生日',null=True,blank=True)
    gender = CharField('性别',max_length=10,choices=gender_choices,default='female')
    address = CharField('地址',max_length=200,default='')
    mobile = CharField('手机号',max_length=11,null=True,blank=True)
    image = ImageField(upload_to='image/%Y%m',default='image/default.png',max_length=100)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '管理员信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class EmailVerifyRecord(Model):
    is_del = IntegerField(default=0)
    '''
    邮件码
    '''
    send_choices = (
        ('register','注册'),
        ('forget','找回密码')
    )

    code = CharField('验证码',max_length=20)
    email = EmailField('邮箱',max_length=50)
    send_type = CharField(choices=send_choices,max_length=10)
    send_time = DateTimeField(default=datetime.now)

    class Meta:
        verbose_name = '邮箱验证码'
        verbose_name_plural = verbose_name


class Banner(Model):
    is_del = IntegerField(default=0)
    '''
    轮播图
    '''
    location = CharField('页面中的位置',max_length=100)
    image = ImageField('轮播图',upload_to='banner/%Y%m',max_length=200)
    url = URLField('访问地址',max_length=200)
    order = IntegerField('顺序',default=100)
    add_time = DateTimeField('添加时间',default=datetime.now)

    class Meta:
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name

class UserWeChat(Model):
    is_del = IntegerField(default=0)
    '''
    微信用户表,微信接口返回的数据
    '''
    openid = CharField("普通用户的标识，对当前开发者帐号唯一",max_length=50)
    nickname = CharField("普通用户昵称",max_length=100)
    sex = IntegerField("普通用户性别，1 为男性，2 为女性",default=1)
    province = CharField("普通用户个人资料填写的省份",max_length=100)
    city = CharField("普通用户个人资料填写的城市",max_length=100)
    country = CharField("国家，如中国为 CN",max_length=100)
    headimgurl = CharField("用户头像",max_length=100)
    # 最后一个数值代表正方形头像大小
    # （有 0、46、64、96、132 数值可选，0 代表 640*640 正方
    privilege = CharField("用户特权信息，json 数组，如微信沃卡用户为（chinaunicom）",max_length=100)
    unionid = CharField("用户统一标识",max_length=100)
    # 。针对一个微信开放平台帐号下的应用，同一用户的 unionid 是唯一的。
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '微信用户'
        verbose_name_plural = verbose_name

class User(Model):
    is_del = IntegerField(default=0)
    '''
    用户表,主表
    '''
    username = CharField('昵称', max_length=50, default='')
    mobile = CharField('手机号', max_length=11, null=True, blank=True)
    birthday = DateField('生日', null=True, blank=True)
    # province_id = ForeignKey(CityDict,verbose_name='所在省份',on_delete=CASCADE)
    # city_id = ForeignKey(CityDict,verbose_name='所在城市',on_delete=CASCADE)
    # area_id = ForeignKey(CityDict,verbose_name='所在区',on_delete=CASCADE)
    address = CharField('地址', max_length=200, default='')
    wechat_id = ForeignKey(UserWeChat,verbose_name='所在区',on_delete=CASCADE)
    add_time = DateTimeField('添加时间', default=datetime.now)

    class Meta:
        verbose_name = '用户表,主表'
        verbose_name_plural = verbose_name